package cn.net.msg.cxf.webservice.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import cn.net.msg.cxf.webservice.IFindWebService;
import cn.net.msg.model.PageView;
import cn.net.msg.model.TbFavourite;
import cn.net.msg.model.TbMood;
import cn.net.msg.service.FindService;
import cn.net.msg.service.base.Order;

@WebService
@SOAPBinding(style = Style.RPC)
@SuppressWarnings("deprecation")
public class FindWebServiceImpl implements IFindWebService {

    @Resource(name = "findService")
    private FindService service;

    @Override
    public List<TbMood> getPopMoodForList(int maxresult, int currentpage) {
        List<TbMood> list = new ArrayList<TbMood>();
        PageView<TbMood> pageView = new PageView<TbMood>(maxresult, currentpage);
        list = service.getPopMoodForList(pageView.getFirstResult(),pageView.getMaxresult(), Order.DESC, "moodPraiseCount");
        if (currentpage == 1) {
            for (TbMood tbMood : list) {
                if (list.indexOf(tbMood) <= 2) {
                    tbMood.setHeatFlag(true);
                }
            }
        }        
        return list;
    }

    @Override
    public List<TbFavourite> getPopFavouriteForList(int maxresult,
            int currentpage) {
        List<TbFavourite> list = new ArrayList<TbFavourite>();
        PageView<TbFavourite> pageView = new PageView<TbFavourite>(maxresult, currentpage);
        list = service.getPopFavouriteForList(pageView.getFirstResult(),pageView.getMaxresult());
        if (currentpage == 1) {
            for (TbFavourite tbFavourite : list) {
                if (list.indexOf(tbFavourite) <= 2) {
                    tbFavourite.setHeatFlag(true);
                }
            }
        }        
        return list;
    }

}
